<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>race方法</title>
</head>

<body>
    <!-- 
        Promise.race方法是需要传递一个参数 参数为数组 数组中的内容表示的是Promise实例化对象
        如果有最先到达状态的(pending来更改成fulfilled或者是rejected)
        不管是成功的状态还是失败的状态 都将以这个对象的状态和结果值为准
     -->
    <script>
        let p1 = new Promise((resolve, reject) => {
            setTimeout(() => {
                resolve('ok')
            }, 3000)
        })
        let p2 = new Promise((resolve, reject) => {
            setTimeout(() => {
                reject('error')
            }, 2000)
        })
        let p3 = new Promise((resolve, reject) => {
            setTimeout(() => {
                resolve('okk,p3')
            }, 1000)
        })
        let result = Promise.race([p1, p2, p3])
        console.log(result)
    </script>
</body>

</html>